import java.util.*;

public class ConvertAnagram {

	static int checkAnagram(String input, String result)
	{
		if(input.equals(result))
			return 1;

		char[] tempInputChar = input.toCharArray();
		char[] tempResultChar = result.toCharArray();

		Arrays.sort(tempInputChar);
		//System.out.println(tempInputChar);

		Arrays.sort(tempResultChar);
		//System.out.println(tempResultChar);
		//if strings not anagrams
		
		String x = new String(tempInputChar);
		String y = new String(tempResultChar);
		if(!(x.equals(y)))
		{
			System.out.println("Yes");
			return 0;
		
		}

		else if(x.equals(y))
		{
			
			return 1;
		}
		return 0;
		
	}

	 int convertAnagram(String input, String result, int startInput, int startResult)
	{
		//System.out.println(input.length());
		int endInput=0;
		//Assumption: strings are anagrams of each other
		//Check if 2 strings are same
			if(input.equals(result))
				return 1;
		//If not same, go ahead
		char[] tempInputChar = input.toCharArray();
		//System.out.println(new String(tempInputChar));	
		char[] tempResultChar = result.toCharArray();
		//System.out.println(new String(tempResultChar));
		//If not, do the following:
			
			//find that letter in input string
				for(int i = 0; i < input.length(); i++)
				{
					//System.out.println(new String(tempInputChar));
					//System.out.println(tempInputChar[0]+","+tempResultChar[startResult]);	
					if (tempInputChar[i] == tempResultChar[startResult])
						{
							//System.out.println(tempInputChar[i]+","+tempResultChar[startResult]);	

							//System.out.println(endInput);	
							endInput = i;
							//System.out.println(endInput);	
							break;
						}
				}
				//from that letter, swap backward till start of input string, till letter is in right place
				
				while((endInput != startResult) && (endInput > 0))
				{
					//swap adjacent letters
					char temp = tempInputChar[endInput];
					tempInputChar[endInput] = tempInputChar[endInput-1];
					tempInputChar[endInput-1] = temp;
					endInput-=1;
					System.out.println(new String(tempInputChar));	
				}
				
			
			
		//Compare next letters recursively, until both the strings are same
			String inputNew = new String(tempInputChar);
			if (startResult+1<result.length() && startInput+1<input.length() ) {
			startResult+=1;
			startInput+=1;			
			}
					
			convertAnagram(inputNew, result, startInput,  startResult);	
			return 0;		
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String input = in.next();
		String result = in.next();
		if(input==null || result==null)
			return;
		ConvertAnagram x = new ConvertAnagram();
		if(x.checkAnagram(input,result)!=0)
		{
		System.out.println(input);
		x.convertAnagram(new String(input),new String(result),0,0);

	}
	else
	{
		System.out.println("Not Anagrams!!! Input again!!");
		

	}
}
	
}
